﻿@using System.Globalization
@using System.Threading
@using EveKillboard.Content
@using EveKillboard.Core.Views
@model IEnumerable<ITopView>
@if (Model is IEnumerable<IItemView>)
{
    <div style="padding-top: 5px;">
        @{ var max = Model.Any() ? (decimal)Model.First().Count : 0; }
        @foreach (var entry in Model)
        {
            <div class="topViewListEntry">
                <div class="topViewListEntryLabel">
                    @if (((IItemView)entry).ItemId > 0){
                        @Html.Raw(string.Format("<a class=\"evelink\" href=\"javascript:CCPEVE.showInfo({0})\">{1}</a>", ((IItemView)entry).ItemId, ((IItemView)entry).ItemName))
                    }
                    else{ <label>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", Labels.unknown)</label> }
                </div>
                <div class="backgroundbar">
                    <div class="innerbar" style="@string.Format(CultureInfo.InvariantCulture, "width:{0:n0}%;", entry.Count / max * 100)" title="@string.Format(Thread.CurrentThread.CurrentCulture, "{0:P0}", entry.Count / max)">
                    </div>
                </div>
                <div class="topViewListEntryCount">@string.Format(Thread.CurrentThread.CurrentCulture, "{0}", entry.Count)</div>
            </div>
        }
    </div>
}
else if (Model is IEnumerable<IItemGroupView>){
    <div style="padding-top: 5px;">
        @{ var max = Model.Any() ? (decimal)Model.First().Count : 0; }
        @foreach (var entry in Model){
            <div class="topViewListEntry">
                <div class="topViewListEntryLabel">@string.Format("{0}", entry.Name)</div>
                <div class="backgroundbar">
                    <div class="innerbar" style="@string.Format(CultureInfo.InvariantCulture, "width:{0:n0}%;", entry.Count / max * 100)" title="@string.Format(Thread.CurrentThread.CurrentCulture, "{0:P0}", entry.Count / max)">
                    </div>
                </div>
                <div class="topViewListEntryCount">@string.Format(Thread.CurrentThread.CurrentCulture, "{0}", entry.Count)</div>
            </div>
        }
    </div>
}
else
{
    if (ViewData["title"] != null){
        <div class="topViewListTitle">@ViewData["title"]</div>
    }
    <div class="topViewHeader">
        @if (ViewData["onclick_previous"] != null){
            <a id="listprevious" onclick="@ViewData["onclick_previous"]">
                <img title="@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", Model is IEnumerable<IMonthView> ? Labels.previous_month : Model is IEnumerable<IWeekView> ? Labels.previous_week : Labels.previous)" width="16px" height="32px" src alt /></a>    
        }
        else{ <div style="width: 16px; height: 16px; display: inline-block;"></div> }
        <img class="@string.Format("topViewHeaderImage {0}", Model is IEnumerable<IKillsView> ? "topViewImageKills" : "topViewImageLosses")" width="64px" height="64px" src alt/>
        <img class="topViewHeaderImage" src="@string.Format("{0}", Model.Any() ? string.Format("http://image.eveonline.com/{1}/{0}_64.{2}", Model.First().EveId, Model is IEnumerable<ICharacterView> ? "Character" : "Corporation", Model is IEnumerable<ICharacterView> ? "jpg" : "png") : Url.Content("~/Content/themes/base/images/blank_tran_64.png"))" width="64px" height="64px" title="@string.Format("{0}", Model.Any() ? Model.First().Name : null)" alt />
        @if (ViewData["onclick_next"] != null){
            <a id="listnext" onclick="@ViewData["onclick_next"]">
                <img title="@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", Model is IEnumerable<IMonthView> ? Labels.next_month : Model is IEnumerable<IWeekView> ? Labels.next_week : Labels.next)" width="16px" height="32px" src alt/></a>
        }
        else{ <div style="width: 16px; height: 16px; display: inline-block;"></div> }
    </div>
    <div>
        @{ var max = Model.Any() ? Model.First() is IValueView ? Model.First().Value : Model.First().Count : 1; }
        @foreach (var entry in Model){
            <div class="topViewListEntry">
                <div class="topViewListEntryLabel">
                    <a class="evelink" href="@string.Format("{0}/{1}", entry is ICharacterView ? Url.Action("Pilot", "Killboard") : Url.Action("Corporation", "Killboard"), entry.InternalId)">@entry.Name</a></div>
                <div class="backgroundbar">
                    <div class="innerbar" style="@string.Format(CultureInfo.InvariantCulture, "width:{0:n0}%;", (entry is IValueView ? entry.Value : entry.Count) / max * 100)" title="@string.Format(Thread.CurrentThread.CurrentCulture, "{0:P0}", (entry is IValueView ? entry.Value : entry.Count) / max )">
                    </div>
                </div>
                <div class="@string.Format("{0}", entry is IValueView ? "topViewListEntryValue" : "topViewListEntryCount")">
                    @if (entry is IValueView){ @string.Format(EveKillboard.Core.EveCustomFormatProvider.Instance, "{0:N2}", entry.Value) }
                    else{ @string.Format(Thread.CurrentThread.CurrentCulture, "{0}", entry.Count) }</div>
            </div>
        }
    </div>
         
}
